/*
 * @Author: cmd
 * @we_chat: cmd_develop
 * @Date: 2018-12-24 21:20:25
 * @LastEditors: cmd
 * @LastEditTime: 2019-01-07 10:25:22
 * @Description: 提示框管理器：加载中、弹框提示
 */

const {ccclass, property} = cc._decorator;

@ccclass
export default class component_alert extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property(cc.Node)
    loading_image: cc.Node = null;

    @property(cc.Label)
    text_label: cc.Label = null;    

    show_tips(text:string){
        this.node.stopAllActions();
        console.log("text：",text);
        this.label.string = text;
        this.node.setPosition(cc.v2(0,0));
        this.node.opacity = 255;
        this.node.active = true;        
        // this.node.width = text.length*30 + 30;
       
        this.label.scheduleOnce(()=>{
            cc.tween(this.node)
                .to(0.5,{position:cc.v2(0,100),opacity:0})                
                .start()

        },1);
    }

    show_loading(text:string){
        let loading_count = 0;
        let loading_count_time = 250;
        this.node.active = true;
        
        this.loading_image.getComponent(cc.Sprite).schedule(()=> {            
            loading_count ++;
            if(loading_count >= loading_count_time)
            {
                this.close_loading();
                //orc.component_manager.show_alert_tips('网络繁忙');
            }
        }, 0.02);

        this.text_label.string= text;
    }

    show_loading_text(text:string){
        this.text_label.string= text;
    }

    close_loading(){        
        this.loading_image.getComponent(cc.Sprite).unscheduleAllCallbacks();
        this.loading_image.angle = 0;
        this.node.active = false;
    }

    // update (dt) {}
}
